<template>
	<div class="allcontainer">
		<div class="h2">{{ $route.query.Name }}</div>
		<div class="bg-white">
		<a-tabs default-active-key="1" @change="tabChange">
			<a-tab-pane key="1" tab="待审批">
				<div id="components-form-demo-advanced-search">
					<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
						<a-row :gutter="24">
							<a-col :span="8">
								<a-form-item label="标题">
									<a-input autocomplete="off" class="field-right" placeholder="请输入标题搜索" v-decorator="[`key`]" />
								</a-form-item>
							</a-col>
							<a-col :span="16">
								<a-button type="primary" html-type="submit">搜索</a-button>
								<a-button @click="handleReset">重置</a-button>
							</a-col>
						</a-row>
					</a-form>
				</div>
				<div class="table">
					<el-table stripe :data="data" v-loading="loading" :max-height="tableHeight" highlight-current-row style="width: 100%;">
						<el-table-column prop="ActivityTitle" label="标题" min-width="130" fixed="left"></el-table-column>
						<el-table-column prop="ChargeUserNo" label="审批节点" min-width="160" align="center">
							<template slot-scope="scope">
								<a-tag color="blue">{{ scope.row.FlowTypeName }}</a-tag>
							</template>
						</el-table-column>
						<el-table-column prop="AddTime" label="时间" min-width="200" align="center"></el-table-column>
						<el-table-column label="操作" width="175" fixed="right">
							<template slot-scope="scope">
								<div class="user-btn">
									<span class="detail" @click="seeList(scope.row)">详情</span>
									<span class="examine" @click="applyHander(scope.row)">审批</span>
								</div>
							</template>
						</el-table-column>
					</el-table>
					<el-pagination
						@size-change="handleSizeChange"
						@current-change="handleCurrentChange"
						:current-page="pagination.currentPage"
						:page-sizes="pagination.pageSizeOptions"
						:page-size="pagination.pageSize"
						layout="total, sizes, prev, pager, next, jumper"
						:total="pagination.total"
					></el-pagination>
				</div>
			</a-tab-pane>
			<a-tab-pane key="2" tab="已审批" force-render>
				<div id="components-form-demo-advanced-search">
					<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch1">
						<a-row :gutter="24">
							<a-col :span="8">
								<a-form-item label="关键字"><a-input autocomplete="off" class="field-right" placeholder="请输入关键字搜索" v-decorator="[`key`]" /></a-form-item>
							</a-col>
							<a-col :span="8" class="option">
								<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
								<a-button :style="{ marginLeft: '8px' }" @click="handleReset1" class="btn2">重置</a-button>
							</a-col>
						</a-row>
					</a-form>
				</div>
				<div>
					<el-table stripe :data="data1" v-loading="loading" :max-height="tableHeight" highlight-current-row style="width: 100%;">
						<el-table-column prop="ActivityTitle" label="标题" min-width="130" fixed="left"></el-table-column>
						<el-table-column prop="ChargeUserNo" label="审批节点" min-width="160" align="center">
							<template slot-scope="scope">
								<a-tag color="blue">{{ scope.row.FlowTypeName }}</a-tag>
							</template>
						</el-table-column>
						<el-table-column prop="ChargeUserNo" label="审批结果" width="90" align="center">
							<template slot-scope="scope">
								<a-tag :color="scope.row.IsAdopt?'blue':'red'">{{ scope.row.IsAdopt?'通过':'驳回' }}</a-tag>
							</template>
						</el-table-column>
						<el-table-column prop="ChargeUserNo" label="审批信息" min-width="120" show-overflow-tooltip>
							<template slot-scope="scope">
								{{ scope.row.ExamComment }}
							</template>
						</el-table-column>
						<el-table-column prop="AddTime" label="时间" width="140" align="center"></el-table-column>
						<el-table-column label="操作" width="120" fixed="right">
							<template slot-scope="scope">
								<i title="详情" class="iconfont icon-xiangqing" style="color: #1890FF;" @click="seeList(scope.row)"></i>
							</template>
						</el-table-column>
					</el-table>
					<el-pagination
						@size-change="handleSizeChange1"
						@current-change="handleCurrentChange1"
						:current-page="pagination.currentPage1"
						:page-sizes="pagination1.pageSizeOptions"
						:page-size="pagination1.pageSize"
						layout="total, sizes, prev, pager, next, jumper"
						:total="pagination1.total"
					></el-pagination>
				</div>
			</a-tab-pane>
		</a-tabs>
	</div>
		<apply :text="text" v-show="applyIf" @closeFun="closeFun"></apply>
		<ActivityDetail :text="text1" v-show="activityMessageIf" @closeFun="closeFun"></ActivityDetail>
	</div>
</template>

<script>
import moment from 'moment';
import apply from './apply';
import ActivityDetail from './ActivityDetail';
import Func from '@/utils/func';
import { UserGetExamPageListActivityFlow, UserGetAlreadyExamPageListActivityFlow, DeleteActivity, GetActivityStateList, GetClubPageListCommon } from '@/api/follow';
const data = [];
const data1 = [];
export default {
	components: {
		apply,
		ActivityDetail
	},
	data() {
		return {
			applyIf: false,
			data,
			data1,
			text1:{},
			activityMessageIf:false,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			pagination1: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			addIf: false,
			text: {},
			visible: false,
			confirmLoading: false,
			itemId: '',
			departmentList: [],
			worklist: [],
			loading: false,
			loading1: false,
			values: {},
			values1: {},
			tableHeight: parseFloat(window.innerHeight - 160),
			ActivityStateList: [],
			ClubList: [],
			tabkey: 1
		};
	},
	computed: {},
	created() {
		this.getList();
		this.getList1();
		this.getOtherList();
	},
	mounted() {},
	methods: {
		moment,
		tabChange(key) {
			this.tabkey = key;
		},
		filterOption(input, option) {
			return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
		},
		async fetchClub(value) {
			let myReg = /^[^a-zA-Z]+$/;
			if (value && value.length>1) {
				let data = {};
				data.key = value;
				let res = await GetClubPageListCommon(data);
				this.ClubList = res.data.data;
			}
		},
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				this.values = values;
				this.getList();
			});
		},
		handleSearch1(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination1.currentPage = 1;
				this.values1 = values;
				this.getList1();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleReset1() {
			this.form.resetFields();
			this.values1 = {};
			this.getList1();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		handleSizeChange1(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange1(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList() {
			this.loading = true;
			let data = {};
			if (this.values) {
				data = this.values;
			}
			data.flowTypeID = this.$route.query.ID
			data.pageIndex = this.pagination.currentPage;
			data.pageSize = this.pagination.pageSize;
			let res = await UserGetExamPageListActivityFlow(data);
			this.loading = false;
			this.data = res.data.data;
			const pagination = { ...this.pagination };
			pagination.total = res.data.pageInfo.TotalItemCount;
			this.pagination = pagination;
		},
		async getList1() {
			this.loading1 = true;
			let data = {};
			if (this.values1) {
				data = this.values1;
			}
			data.pageIndex = this.pagination1.currentPage;
			data.pageSize = this.pagination1.pageSize;
			data.flowTypeID = this.$route.query.ID
			let res = await UserGetAlreadyExamPageListActivityFlow(data);
			this.loading1 = false;
			this.data1 = res.data.data;
			const pagination = { ...this.pagination1 };
			pagination.total = res.data.pageInfo.TotalItemCount;
			this.pagination1 = pagination;
		},
		async getOtherList() {
			let res = await GetActivityStateList();
			this.ActivityStateList = res.data.data;
			let res1 = await GetClubPageListCommon();
			this.ClubList = res1.data.data;
		},
		addList() {
			this.text = {};
			this.addIf = !this.addIf;
		},
		seeList(item) {
			this.text1 = { ...item,time:new Date() }
			this.activityMessageIf = true
		},
		applyHander(item) {
			this.text = item;
			this.applyIf = true;
		},
		closeFun(data) {
			this.applyIf = false;
			this.activityMessageIf = false
			if (data == 1) {
				this.getList();
				this.getList1();
			}
		}
	}
};
</script>

<style lang="less" scoped>

/deep/.searchform .ant-form-item-label{
	display: flex;
	align-items: center;
}
</style>
